import { useEffect, useState, useRef } from 'react';
import { useEnv, gatewayRequest } from '@ydc/workbench-tools';
import { Upload as F2eUpload } from '@ydc/f2e-components';
import { Button, Upload } from 'antd';
import { rpcRequest } from '@/services/base';
import getParamByKey from '@/utils/getParamByKey';
import { useUpload } from '@/utils/upload';
import _ from 'lodash';
import './index.less';

export default () => {
  const { uploadFiles } = useUpload();
  //  正常请求
  const list = () => {
    gatewayRequest('biz/ka/cmda/getExamApplyList.json', {
      param: {
        appId: env.appId,
        params: { ...params, exam_plan_id: getParamByKey('id') },
      },
    }).then((res) => {
      /** 后续处理 */
    });
  };

  // 服务编排
  const detail = () => {
    rpcRequest('/gateway/runtime/runByName', {
      graphName: 'getExamApplyPlanDetail',
      appId: env.appId,
      input: {
        id: getParamByKey('id'),
      },
    }).then((res) => {
      /** 后续处理 */
    });
  };

  const customRequest = async (options: File[]) => {
    const { file } = options;
    const result = await uploadFiles([file]);
    console.log(result, 'result');
  };

  const demoRequest = async (files: any) => {
    const result = await uploadFiles(files);
    return result; // 必须返回结果
  };

  /**自定义上传*/
  return (
    <div className="demo">
      <p>1.这个是平台的上传，里面封装好了oss上传和minio上传，建议直接使用，</p>
      <F2eUpload>
        <span>上传</span>
      </F2eUpload>

      <p>2.平台组件自定义上传</p>
      <F2eUpload customRequest={demoRequest}>
        <span>上传</span>
      </F2eUpload>

      <p>3.这个是自定义上传</p>
      <Upload customRequest={customRequest}>
        <span>上传</span>
      </Upload>
    </div>
  );
};
